package com.ccq.service;

import com.alibaba.fastjson.JSON;
import com.ccq.mapper.SecondMapper;
import com.ccq.model.Second;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LastAllService {
    @Autowired
    SecondMapper secondMapper;

    public String secondlist(Integer page){
        page=(page-1)*5;
        List<Second> ls=secondMapper.selectPage(page);
        String aListJson = JSON.toJSONString(ls);
        System.out.println(aListJson);
        return aListJson;
    }

    public int add(Second second){
        int add=secondMapper.insertSelective(second);
        System.out.println(add);
        return add;
    }

    public String eidts(int id){
        Second se=secondMapper.selectByPrimaryKey(id);
        String aListJson = JSON.toJSONString(se);
        return aListJson;
    }

    public String edit(Second second){
        int  se=secondMapper.updateByPrimaryKey(second);
        List<Second> ls=secondMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        return aListJson;
    }

    public String del(int id){
        int del=secondMapper.deleteByPrimaryKey(id);
        List<Second> ls=secondMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        System.out.println("删除成功！");
        return aListJson;
    }
}
